
<!DOCTYPE html>
<html lang="zh-cn">

<head>
<meta charset="utf-8" />
<meta name="author" content="TianShangXing" />
<meta name="description" content="Personal blog." />
<meta name="keywords" content="blog, tech" />
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<meta name="generator" content="Hugo 0.68.3" />

<link rel="canonical" href="https://tianshangxing.gitee.io/myblog/">
<meta property="og:title" content="TianShangXing&#39;s Blog" />
<meta property="og:description" content="" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://tianshangxing.gitee.io/myblog/" />
<meta property="og:updated_time" content="2020-04-08T16:08:54+08:00" />

<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="TianShangXing&#39;s Blog"/>
<meta name="twitter:description" content=""/>


<meta itemprop="name" content="TianShangXing&#39;s Blog">
<meta itemprop="description" content="">

<link rel="stylesheet" href="https://tianshangxing.gitee.io/myblog/css/layout.css" />


<link rel="stylesheet" href="https://tianshangxing.gitee.io/myblog/css/default-dark.css" />




<title>


    TianShangXing&#39;s Blog

</title>

</head>


<body>
<div class="main">
<header>

<div class="header-bar">

  <nav>
    <div class="siteTitle">
      <a href="https://tianshangxing.gitee.io/myblog">TianShangXing&#39;s Blog</a>
    </div> 

    
    
    <a class="nav-item" href="https://tianshangxing.gitee.io/myblog/blog/"><div class="nav-item-title">Blogs</div></a>
    
    <a class="nav-item" href="https://tianshangxing.gitee.io/myblog/resume/"><div class="nav-item-title">Resume</div></a>
    

  </nav>

  
<div class="social-links-header">

  
  <a href="mailto:tian_shang_xing@foxmail.com"><div class="social-link">email</div></a>
  

  
  <a href="https://github.com/TianShangXing" target="_blank"><div class="social-link">gh</div></a>
  

  

  

  
  <a href="https://www.linkedin.com/in/%e6%98%9f%e4%bc%b8-%e5%88%98-b7b7321a6" target="_blank"><div class="social-link">in</div></a>
  

</div>


</div>


</header>


<main>


  
    <article class="post-preview">

  <header>
    <h2 class="title"> <a href='https://tianshangxing.gitee.io/myblog/blog/%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0%E9%AA%8C%E8%AF%81%E7%A0%81%E5%8A%9F%E8%83%BD/'> 代码实现验证码功能</a> </h2>
    <div class="meta">
      <div class="date">
      29 Apr, 2020 - 2 minutes
      </div>
      
<div class="tags">
  
</div>

    </div>

  </header>

  <div class="summary">
    现在大部分网址登录时都需要输验证码才允许登录，在这里我用python代码来实现手写一套验证码逻辑
Django后端代码 # 导入图片库 # 绘画库 from PIL import ImageDraw # 字体库 from PIL import ImageFont # 图片库 from PIL import Image # 随机库 import random # 文件流 import io # 自定义图片验证码 class MyCode(View): # 定义RGB随机颜色 def get_random_color(self): R = random.randrange(255) G = random.randrange(255) B = random.randrange(255) return(R, G, B) # 定义图片视图 def get(self, request): # 画布 img_size = (130, 60) # 定义图片对象 image = Image.new('RGB', img_size, '#FFFFE0') # 定义画笔 draw = ImageDraw.
  </div>

  <div class="rmore">
    <a href='https://tianshangxing.gitee.io/myblog/blog/%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0%E9%AA%8C%E8%AF%81%E7%A0%81%E5%8A%9F%E8%83%BD/' class="rmore">Read more</a>
  </div>


</article>


    <article class="post-preview">

  <header>
    <h2 class="title"> <a href='https://tianshangxing.gitee.io/myblog/blog/%E7%99%BE%E5%BA%A6%E6%99%BA%E8%83%BD%E4%BA%91%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB/'> 百度智能云文字识别</a> </h2>
    <div class="meta">
      <div class="date">
      28 Apr, 2020 - 1 minutes
      </div>
      
<div class="tags">
  
</div>

    </div>

  </header>

  <div class="summary">
    现在好多的网址在登录时都需要输入验证码才能够登录成功，防止被恶意登录
今天我就教你们一招用百度智能云来帮助我们破解验证码
首先，先申请百度智能云： https://cloud.baidu.com/
然后在人工智能 -&gt; 文字识别模块 新建一个应用
建立成功后，会分配给你一个key和secret
只不过这个接口免费版的每秒最多只能请求两次，一天有500次的请求机会
这里推荐使用高精度的接口，普通的识别率太差了
在帮助文档里找到 通用文字识别（高精度版）
第一步，获取access_token
# 获取token res = requests.get(&quot;https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&amp;client_id=你的key&amp;client_secret=你的秘钥&quot;) res = json.loads(str(res.text)) token = res['access_token'] 然后请求高精度识别接口，需要注意一点，这里图片需要转换成base64编码
# 接口地址 url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=' + token # 定义头部信息 myheaders = {'Content-Type': 'application/x-www-form-urlencoded'} # 操作图片 myimg = open('./code.png', 'rb') # 读取图片 temp_img = myimg.read() myimg.close() # 进行base64编码 temp_data = {'image':base64.b64encode(temp_img)} # 对图片地址进行urlencode操作 temp_data = urllib.parse.urlencode(temp_data) # 请求视图接口 res = requests.post(url=url, data=temp_data, headers=myheaders) code = res.
  </div>

  <div class="rmore">
    <a href='https://tianshangxing.gitee.io/myblog/blog/%E7%99%BE%E5%BA%A6%E6%99%BA%E8%83%BD%E4%BA%91%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB/' class="rmore">Read more</a>
  </div>


</article>


    <article class="post-preview">

  <header>
    <h2 class="title"> <a href='https://tianshangxing.gitee.io/myblog/blog/md5%E5%8A%A0%E5%AF%86/'> MD5加密</a> </h2>
    <div class="meta">
      <div class="date">
      23 Apr, 2020 - 1 minutes
      </div>
      
<div class="tags">
  
</div>

    </div>

  </header>

  <div class="summary">
    MD5加密算法  代码实现
# 导入加密库 import hashlib # md5加密方法 def make_password(mypass): # 生成md5对象 md5 = hashlib.md5() # 转码操作 mypass_utf8 = str(mypass).encode(encoding=&quot;utf-8&quot;) # 加密操作 md5.update(mypass_utf8) # 返回密文 return md5.hexdigest() 
  </div>

  <div class="rmore">
    <a href='https://tianshangxing.gitee.io/myblog/blog/md5%E5%8A%A0%E5%AF%86/' class="rmore">Read more</a>
  </div>


</article>


    <article class="post-preview">

  <header>
    <h2 class="title"> <a href='https://tianshangxing.gitee.io/myblog/blog/heyui/'> HeyUI</a> </h2>
    <div class="meta">
      <div class="date">
      23 Apr, 2020 - 1 minutes
      </div>
      
<div class="tags">
  
</div>

    </div>

  </header>

  <div class="summary">
    HeyUI  HeyUI 是一套基于 Vue2.0 的开源 UI 组件库，主要服务于一些中后台产品。
HeyUI 是一个自动化图形化界面组件，便于后端研发入手前端。
HeyUI 提供的是一整套解决方案，所有的组件提供全局的可配置模式
官网： https://www.heyui.top/
安装 npm install heyui --save
使用 import HeyUI from 'heyui'; Vue.use(HeyUI); new Vue({ el: '#app', router, components: { App }, template: '&lt;App/&gt;', render: h =&gt; h(App) }) 
  </div>

  <div class="rmore">
    <a href='https://tianshangxing.gitee.io/myblog/blog/heyui/' class="rmore">Read more</a>
  </div>


</article>


    <article class="post-preview">

  <header>
    <h2 class="title"> <a href='https://tianshangxing.gitee.io/myblog/blog/django/'> Django</a> </h2>
    <div class="meta">
      <div class="date">
      22 Apr, 2020 - 1 minutes
      </div>
      
<div class="tags">
  
</div>

    </div>

  </header>

  <div class="summary">
    Django Django是一个开放源代码的Web应用框架，由Python写成。采用了MVT的软件设计模式，即模型（Model），视图（View）和模板（Template）。
安装依赖 pip install Django==2.0.4 pip install django-cors-headers pip install djangorestframework pip install PyMySQL pip install opencv-python pip install opencv-contrib-python pip install numpy pip install pillow pip install dwebsocket 依赖文件生成 requirements.txt pip freeze &gt; requirements.txt 依赖文件安装 requirements.txt pip install -r requirements.txt 新建Django项目 django-admin startproject mydjango 新建子应用 python manage.py startapp myapp 数据库迁移 python manage.py makemigrations myapp python manage.py migrate 反向迁移 python manage.py inspectdb &gt; mymodels.py 启动项目 python manage.py runserver 项目仓库： https://github.
  </div>

  <div class="rmore">
    <a href='https://tianshangxing.gitee.io/myblog/blog/django/' class="rmore">Read more</a>
  </div>


</article>




<div class="page-nav">
  <div class="page-prev">
    
  </div> 

  <div class="page-num">
    1/5
  </div> 

  <div class="page-next">
    
    <a href="https://tianshangxing.gitee.io/myblog/page/2/" title="Next page"> >> </a>
    
  </div> 
</div> 


</main>

  <footer>

  <div class="social-links-footer">

  
  <a href="mailto:tian_shang_xing@foxmail.com"><div class="social-link">Email</div></a>
  

  
  <a href="https://github.com/TianShangXing" target="_blank"><div class="social-link">GitHub</div></a>
  

  

  

  
  <a href="https://www.linkedin.com/in/%e6%98%9f%e4%bc%b8-%e5%88%98-b7b7321a6" target="_blank"><div class="social-link">LinkedIn</div></a>
  

  <div class="social-link">
  <a href="https://tianshangxing.gitee.io/myblog/index.xml" target="_blank">RSS</a>
  </div>

</div>


  <div class="copyright"> Copyright (c) 2020, all rights reserved. </div>

  <div class="poweredby">
    Powered by <a href="https://gohugo.io/">Hugo</a>.
  </div>

  </footer>

</div> 

</body>
</html>

